package connects

import (
	"golang.org/x/net/websocket"
)

type Connects struct {
	list map[int64]*websocket.Conn
}

var Service *Connects

func Init() {
	Service = &Connects{
		list: make(map[int64]*websocket.Conn),
	}
	return
}

func (connects *Connects) Add(userId int64, conn *websocket.Conn) {
	connects.list[userId] = conn
}
func (connects *Connects) Delete(userId int64) {
	delete(connects.list, userId)
}
func (connects *Connects) Get(userId int64) (con *websocket.Conn) {
	conn, ok := connects.list[userId]
	if !ok {
		return nil
	}
	return conn
}

func (connects *Connects) GetLists() (data []*websocket.Conn) {
	clients := make([]*websocket.Conn, 0)
	var i = 0
	for _, v := range connects.list {
		i++
		clients = append(clients, v)
	}
	return clients
}

func (connects *Connects) GetUserLists() (data map[int64]*websocket.Conn) {
	return connects.list
}
